package com.study.agp.transition;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.study.agp.databinding.AdapterSampleItemBinding;

import java.util.List;

public class SamplesRecyclerAdapter extends RecyclerView.Adapter<SamplesRecyclerAdapter.SampleViewHolder> {
    private final List<Sample> sampleList;

    public SamplesRecyclerAdapter(List<Sample> sampleList) {
        this.sampleList = sampleList;
    }

    @NonNull
    @Override
    public SampleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        AdapterSampleItemBinding binding = AdapterSampleItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new SampleViewHolder(binding.getRoot());
    }

    @Override
    public void onBindViewHolder(@NonNull SampleViewHolder holder, int position) {
        Sample sample = this.sampleList.get(position);
        holder.binding.setSample(sample);
        holder.binding.sampleLayout.setOnClickListener(v -> {
            switch (holder.getAdapterPosition()) {
                case 0:
                    break;
            }
        });
    }

    @Override
    public int getItemCount() {
        return this.sampleList != null ? this.sampleList.size() : 0;
    }

    static class SampleViewHolder extends RecyclerView.ViewHolder {
        AdapterSampleItemBinding binding;
        public SampleViewHolder(@NonNull View itemView) {
            super(itemView);
            binding = DataBindingUtil.bind(itemView);
        }
    }
}
